<?php

/**
 * @author Ismael Gonzalez
 * @copyright 2010
 * Handler Comentarios
 */
include_once('classUtils.php');

class Comentarios{
	public function sendComments($notaid, $username, $email, $comentario){
		$SQL = "INSERT INTO comentarios (notaid, user, email, comentario, fechaCreado, ipAddress) "
			."VALUES (".$notaid.", '".$username."', '".$email."', '"
			.$comentario."', '".date('Y-m-d H:i')."', '".$_SERVER['REMOTE_ADDR']."')";
		$Q = mysql_query($SQL) or die(mysql_error());
	}
	
	public function getComments($notaid){
		$SQL = "SELECT user, comentario, fechaCreado FROM comentarios WHERE notaid = "
				.$notaid." AND status='A' ORDER BY fechaCreado DESC";
		$Q = mysql_query($SQL) or die(mysql_error());
		
		$arrRes = Array();
		$i = 0;	
		$Utils = new Utils();
		
		while($row = mysql_fetch_array($Q)){
			$arrRes[$i]['fechaCreado'] = $Utils->setFechaHora($row["fechaCreado"]); 
			$arrRes[$i]['user'] = $row["user"]; 
			$arrRes[$i]['comentario'] = $row["comentario"];			
			$i++;
		}
		return $arrRes;
	}
	
		public function getCommentsFoto($fotoid){
		$SQL = "SELECT user, comentario, fechaCreado FROM comentariosFotos WHERE fotoid = "
				.$fotoid." AND status='A' ORDER BY fechaCreado DESC";
		$Q = mysql_query($SQL) or die(mysql_error());
		
		$arrRes = Array();
		$i = 0;	
		$Utils = new Utils();
		
		while($row = mysql_fetch_array($Q)){
			$arrRes[$i]['fechaCreado'] = $Utils->setFechaHora($row["fechaCreado"]); 
			$arrRes[$i]['user'] = $row["user"]; 
			$arrRes[$i]['comentario'] = $row["comentario"];			
			$i++;
		}
		return $arrRes;
	}	
	
	public function sendCommentsFoto($fotoid, $username, $email, $comentario){
		$SQL = "INSERT INTO comentariosFotos (fotoid, user, email, comentario, fechaCreado) "
			."VALUES (".$fotoid.", '".$username."', '".$email."', '"
			.$comentario."', '".date('Y-m-d H:i')."')";

		$Q = mysql_query($SQL) or die(mysql_error());
	}
}

?>
